<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="../cwjy/css/app.css" rel="stylesheet">
    <style>
        html::-webkit-scrollbar {
            display: none
        }
    </style>
</head>
<script src="../cwjy/js/app.js"></script>
<script src="../cwjy/js/jquery.min.js"></script>
<body>
<div class="card">
    <div class="card-header">
        <div>
            <div style="float:left;">
                <span style="font-weight: bold;font-size: 20px;text-shadow: 1px 1px 2px #000000;">订单查询</span>
            </div>
        </div>
        <table class="table table-striped" cellpadding="0" cellspacing="0">
            <thead>
            <tr>
                <th style="width:5%;">序号</th>
                <th style="width:20%;">订单编号</th>
                <th style="width:10%">订单总额</th>
                <th style="width:10%">创建时间</th>
                <th style="width:10%">付款时间</th>
                <th style="width:10%">发货时间</th>
                <th class="d-none d-md-table-cell" style="width:10%">创建人</th>
                <th style="width:15%">交易状态</th>
                <th>交易操作</th>
            </tr>
            </thead>
            <tbody id="tbodyDataDiv">
            <tr>
                <td>1</td>
                <td>耐克潮牌鞋</td>
                <td><img src="../cwjy/img/avatars/avatar-2.jpg" style="width: 40px;height: 40px;"></td>
                <td>999</td>
                <td>888</td>
                <td>F1333457</td>
                <td>2018-12-12</td>
                <td>
                    <p>交易成功</p>
                    <p><a href="#" style="color: #495057" data-toggle="modal"
                          data-target="#defaultModalPrimary" onclick="ckxx()">订单详细</a></p>
                    <p><a href="#" style="color: #495057">查看物流</a></p>
                </td>
                <td class="d-none d-md-table-cell">
                    <p><a href="#" style="color: #495057;box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0
                     rgba(0,0,0,0.19);" class="btn btn-outline-secondary" data-toggle="modal"
                          data-target="#defaultModalPrimary" onclick="ddPJ()">评价</a></p>

                    <p><a href="#" style="color: #495057;box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0
                     rgba(0,0,0,0.19);" class="btn btn-outline-secondary" onclick="ljfk()">立即付款</a></p>

                    <p><a href="#"
                          style="color: #495057;box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);"
                          class="btn btn-outline-secondary" data-toggle="modal"
                          data-target="#defaultModalPrimary" onclick="sqsh()">申请售后</a></p>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

<!--模态框-->

<div class="modal fade" id="defaultModalPrimary" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content" id="contentModel">
            <div class="modal-header" id="modelHead">
                <h3 class="modal-title" id="modelHeadText" style="font-weight: bold;text-shadow: 1px 1px 3px #000000;">
                    收货地址详细</h3>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body m-3">
                <div class="card-body" id="modelDiv"
                     style="margin-top: -4%;text-shadow: 2px 2px 2px #cccccc;font-weight: bold">

                </div>
            </div>
            <div class="modal-footer" id="modelAction">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                <!--<button type="button" class="btn btn-primary" >提交</button>-->
            </div>
        </div>
    </div>
</div>


<!--模态框-->
<!--
<div class="modal fade" id="defaultModalPrimary1" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="width: 150%;border: 1px solid #000">
            <div class="modal-header" id="modelHead1">
                <h3 class="modal-title" id="modelHeadText1" style="font-weight: bold;text-shadow: 1px 1px 3px #000000;">
                    订单详细</h3>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body m-3">
                <div class="card-body" id="modelDiv1" style="margin-top: -6%;" >
                    <h3 style="text-shadow: 1px 1px 3px #000000;">商品名称</h3>
                    <p class="text-muted" style="font-weight: bold">耐克球鞋</p>
                    <h3 style="text-shadow: 1px 1px 3px #000000;">商品图片</h3>
                </div>
            </div>
            <div class="modal-footer" id="modelAction1">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                &lt;!&ndash;<button type="button" class="btn btn-primary" >提交</button>&ndash;&gt;
            </div>
        </div>
    </div>
</div>-->

<script type="text/javascript" src="../cwjy/js/ajaxAll.js"></script>
<script type="text/javascript">


    let OrderData;


    function getOrderData() {
        $.ajax({
            type: 'post',
            async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
            url: 'http://localhost:8888/cwjy/Order/getPage',    //请求发送到Servlet
            contentType: 'application/json;charset=UTF-8',//指定消息请求类型
            data: JSON.stringify({}),
            timeout: 10000,    //超时10s
            success: function (res) { returnLogin(res);
                OrderData = res.data;
                forEachOrderData(res.data)
            },
            error: function (errorMsg) {
                //请求失败时执行该函数
                alert('数据请求失败!');
            }
        });
    }

    function getOrderByIdData(id) {
        for (let i = 0; i < OrderData.length; i++) {
            if (OrderData[i].id === id) {
                return OrderData[i];
            }
        }
    }

    function forEachOrderData(data) {
        let tbodyDataDiv = "";
        for (let i = 0; i < data.length; i++) {


            let pj = "<p style=\"\"><a href=\"#\" style=\"color: #495057;box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0\n" +
                "                     rgba(0,0,0,0.19);\" class=\"btn btn-outline-secondary\" data-toggle=\"modal\" data-target=\"#defaultModalPrimary\" onclick=\"ddPJ('" + data[i].id + "')\">评价</a></p>";

            let ljfk = "<p style=\"\"><a href=\"#\" style=\"color: #495057;box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0\n" +
                "                     rgba(0,0,0,0.19);\" class=\"btn btn-outline-secondary\" onclick=\"ljfk()\">立即付款</a></p>";

            let sqsh = "<p style=\"\"><a href=\"#\" style=\"color: #495057;box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);\" class=\"btn btn-outline-secondary\" data-toggle=\"modal\"" +
                " data-target=\"#defaultModalPrimary\" onclick=\"sqsh('" + data[i].id + "','" + data[i].commodity_id + "')\">申请售后</a></p>";

            let zcsq = "<p style=\"\"><a href=\"#\" style=\"color: #495057;box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);\" class=\"btn btn-outline-secondary\" data-toggle=\"modal\"" +
                " data-target=\"#defaultModalPrimary\" onclick=\"requestRefundAgainInit('" + data[i].id + "','" + data[i].commodity_id + "')\">再次申请</a></p>";


            let txwl = "<p><a href=\"#\" style=\"color: #495057;box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0\n" +
                "rgba(0,0,0,0.19);\" class=\"btn btn-outline-secondary\" data-toggle=\"modal\" data-target=\"#defaultModalPrimary\" onclick=\"txwl()\">填写物流</a></p>"

            let qrsh = "<p><a href=\"#\" style=\"color: #495057;box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0\n" +
                "rgba(0,0,0,0.19);\" class=\"btn btn-outline-secondary\" onclick=\"qrsh('" + data[i].id + "')\">确认收货</a></p>"


            let buttonDiv = "";
            let orderStatus = ""
            if (data[i].status === 2) {
                buttonDiv = sqsh;
                orderStatus = "交易中 - 待发货";
            }

            if (data[i].status === 3) {
                buttonDiv = sqsh;
                orderStatus = "交易中 - " + data[i].status_name;
            }

            if (data[i].status === 1) {
                buttonDiv = ljfk;
                orderStatus = "交易中 - " + data[i].status_name;
            }

            if (data[i].status === 4) {
                buttonDiv = sqsh + qrsh;
                orderStatus = "交易中 - " + data[i].status_name;
            }

            if (data[i].status === 6) {
                if (data[i].buyer_rate === 0) {
                    buttonDiv = pj
                    orderStatus = data[i].status_name;
                } else {
                    orderStatus = data[i].status_name + " - 已评价";
                }

            }

            if (data[i].status === 5) {
                orderStatus = data[i].status_name + " - " + data[i].order_return_entity.status_name
                if (data[i].order_return_entity.status === 3) {
                    orderStatus = data[i].status_name + " - 等待商家确认收货";
                }
                if (data[i].order_return_entity.status === 2) {
                    buttonDiv = txwl
                }
                if (data[i].order_return_entity.status === 0) {
                    buttonDiv = zcsq
                }
            }
            if (data[i].status === 7) {
                orderStatus = data[i].status_name + " - " + data[i].order_return_entity.status_name;
            }

            /*    let imagesCommodity = "";
                let priceCommodity = "";
                let paymentName = "";

                for (let j = 0; j < data[i].order_item_entity.length; j++) {
                    let imagesCommodityTemp = "<p><img src=\"http://localhost:8888/cwjy/images/"+data[i].order_item_entity[j].pic_path+"\" style=\"width: 40px;height: 40px;\"></p>";
                    let priceCommodityTemp = "<p>"+data[i].order_item_entity[j].price+" * "+data[i].order_item_entity[j].num+"</p>"
                    let paymentNameTemp = "<p>"+data[i].order_item_entity[j].commodity_entity.product_name+"</p>"
                    imagesCommodity += imagesCommodityTemp;
                    priceCommodity += priceCommodityTemp;
                    paymentName += paymentNameTemp;
                }
                */


            let temp = " <tr>\n" +
                "                <td>" + (i + 1) + "</td>\n" +
                "                <td>" + data[i].id + "</td>\n" +
                "                <td>" + data[i].payment + "</td>\n" +
                "                <td>" + data[i].create_date + "</td>\n" +
                "                <td>" + data[i].payment_time + "</td>\n" +
                "                <td>" + data[i].consigo_time + "</td>\n" +
                "                <td>" + data[i].create_user + "</td>\n" +
                "                <td>\n" +
                "                    <p>" + orderStatus + "</p>\n" +
                "                    <p><a href=\"#\" style=\"color: #495057\" data-toggle=\"modal\"\n" +
                "                          data-target=\"#defaultModalPrimary\" onclick=\"ckxx('" + data[i].id + "')\">订单详细</a></p>\n" +
                "                    <p><a href=\"#\" style=\"color: #495057\" data-toggle=\"modal\"\n" +
                "                          data-target=\"#defaultModalPrimary\" onclick=\"viewShippingAddress('" + data[i].id + "')\">查看收货地址</a></p>\n" +
                "                </td>\n" +
                "                <td class=\"d-none d-md-table-cell\">\n" +
                "         " + buttonDiv + "       </td>\n" +
                "            </tr>";
            tbodyDataDiv += temp;
        }
        $('#tbodyDataDiv').html(tbodyDataDiv);
    }

    /**再次申请*/
    function requestRefundAgainInit(id, commodity_id) {
        let data = getOrderByIdData(id);
        let productName = "";
        let productImages = "";
        let productData = data.order_item_entity;
        for (let i = 0; i < productData.length; i++) {
            productName += productData[i].commodity_entity.product_name + " , ";
            let tempImages = "<img src=\"http://localhost:8888/cwjy/images/" + productData[i].pic_path + "\" style=\"width: 100px;height: 100px;\">";
            productImages += tempImages;
        }


        let modelHead = "  <h3 class=\"modal-title\" id=\"modelHeadText\" style=\"font-weight: bold;text-shadow: 1px 1px 3px #000000;\">\n" +
            "                    订单售后</h3>\n" +
            "                <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\">\n" +
            "                    <span aria-hidden=\"true\">×</span>\n" +
            "                </button>";
        let modelBody = "  <h3 style=\"text-shadow: 1px 1px 3px #000000;\">商品名称</h3>\n" +
            "                    <p class=\"text-muted\" style=\"font-weight: bold\">" + productName + "</p>\n" +
            "                    <h3 style=\"text-shadow: 1px 1px 3px #000000;\">商品图片</h3>\n" +
            "                    <p class=\"text-muted\" style=\"font-weight: bold\">" + productImages + "" +
            "</p>\n" +
            "                    <h3 style=\"text-shadow: 1px 1px 3px #000000;\">选择服务类型</h3>\n" +
            "                    <p id=\"returnButton\">\n" +
            "                        <button type=\"button\" id ='1' style=\"width: 49%;height: 100px;font-weight: bold\" class=\"btn btn-outline-secondary\">\n" +
            "                                我要退款(无需退货)\n" +
            "                                 <p>没收到或,或与卖家协商同意不用退货只退款</p>\n" +
            "                        </button>\n" +
            "                        <button type=\"button\" id ='2' class=\"btn btn-outline-secondary\" style=\"width:49%;height: 100px;font-weight: bold;background-color: #6c757d;color: #ffffff\">\n" +
            "                            我要退货退款\n" +
            "                            <p>已收到货,需要退还收到的货物</p>\n" +
            "                        </button>\n" +
            "                    </p>\n" +
            "                    <h3 style=\"text-shadow: 1px 1px 3px #000000;\">退款说明</h3>\n" +
            "                    <p class=\"text-muted\" style=\"font-weight: bold\">\n" +
            "                        <textarea style=\"resize: none;width: 70%;height: 100px;\" id='refund_instructions'></textarea>\n" +
            "                    </p>";
        let modelAction = " <button type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">关闭</button>\n" +
            "                 <button type=\"button\" class=\"btn btn-primary\" id='submitButton' onclick=\"requestRefundAgain('"+id+"')\">提交</button>";
        $('#modelHead').html(modelHead)
        $('#modelDiv').html(modelBody)
        $('#modelAction').html(modelAction)
        $('#returnButton button').unbind("click")
        $('#returnButton button').click(function () {
            $("#returnButton button").each(function () {
                $(this).css("background-color", "#ffffff")
                $(this).css("color", "#6c757d")
            })
            $(this).css("background-color", "#6c757d")
            $(this).css("color", "#ffffff")
        })
    }

    function requestRefundAgain(id) {
        let refund_instructions = $('#refund_instructions').val();
        let refund_type = 1;
        $("#returnButton button").each(function () {
            let background = $(this).css("background-color");
            if (background === 'rgb(108, 117, 125)') {
                refund_type = $(this)[0].id;
            }
        });
        let url = "http://localhost:8888/cwjy/OrderReturn/requestRefundAgain";
        let json = {"order_id": id,"refund_instructions": refund_instructions,"refund_type": refund_type};
        let success = "申请成功！";
        let error = "申请失败";
        if (confirm("请确认是否重新申请退货！")) {
            ajaxAddUpdate(url, json, success, error)
        }
    }


    /**确认收货*/
    function qrsh(id) {
        let url = "http://localhost:8888/cwjy/Order/confirmReceipt";
        let json = {"id": id};
        let success = "收货成功！";
        let error = "收货失败";
        if (confirm("请确认是否收货！")) {
            ajaxAddUpdate(url, json, success, error)
        }
    }

    function viewShippingAddress(id) {
        let data = getOrderByIdData(id).order_shipping_entity;
        let modelHead = "  <h3 class=\"modal-title\" id=\"modelHeadText\" style=\"font-weight: bold;text-shadow: 1px 1px 3px #000000;\">\n" +
            "                    收货地址详细</h3>\n" +
            "                <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\">\n" +
            "                    <span aria-hidden=\"true\">×</span>\n" +
            "                </button>";
        let modelBody = data.receiver_state + " " + data.receiver_city + " " + data.receiver_district + " " + data.receiver_address + " ";
        let modelAction = "   <button type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">关闭</button>\n";
        $('#modelHead').html(modelHead)
        $('#modelDiv').html(modelBody)
        $('#modelAction').html(modelAction)
    }


    /**填写退货物流单号*/
    function txwl() {
        let modelHead = "    <h3 class=\"modal-title\" id=\"modelHeadText\" style=\"font-weight: bold;text-shadow: 1px 1px 3px #000000;\">\n" +
            "                    填写退货物流单号</h3>\n" +
            "                <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\">\n" +
            "                    <span aria-hidden=\"true\">×</span>\n" +
            "                </button>";
        let modelBody = "   <div class=\"mb-3 row\" style='font-weight: bold;text-shadow: 1px 1px 3px #000000;'>\n" +
            "                        <label class=\"col-form-label col-sm-2 text-sm-right\">物流单号</label>\n" +
            "                        <div class=\"col-sm-10\">\n" +
            "                            <input type=\"text\" id=\"shipping_code\" class=\"form-control\" placeholder=\"物流单号\" rows=\"3\">\n" +
            "                        </div>\n" +
            "                    </div>";
        let modelAction = "   <button type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">关闭</button>\n" +
            "                <button type=\"button\" class=\"btn btn-primary\" id=\"submitId\">提交</button>";
        $('#modelHead').html(modelHead)
        $('#modelDiv').html(modelBody)
        $('#modelAction').html(modelAction)
    }


    getOrderData();

    /**查看详细*/
    function ckxx(id) {
        $('#contentModel').css("width", "150%")
        $('#contentModel').css("margin-left", "-25%")
        let data = getOrderByIdData(id);

        let modelHead = "  <h3 class=\"modal-title\" id=\"modelHeadText\" style=\"font-weight: bold;text-shadow: 1px 1px 3px #000000;\">\n" +
            "                    订单详细</h3>\n" +
            "                <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\">\n" +
            "                    <span aria-hidden=\"true\">×</span>\n" +
            "                </button>";
        let modelBody = "  <table class=\"table table-striped\" cellpadding=\"0\" cellspacing=\"0\">\n" +
            "                        <thead>\n" +
            "                        <tr>\n" +
            "                            <th style=\"width:5%;\">序号</th>\n" +
            "                            <th style=\"width:10%;\">商品名称</th>\n" +
            "                            <th style=\"width:10%\">商品图片</th>\n" +
            "                            <th style=\"width:10%\">商品单价</th>\n" +
            "                            <th style=\"width:10%\">数量</th>\n" +
            "                            <th style=\"width:10%\">商品规格</th>\n" +
            "                            <th style=\"width:10%\" >实付款</th>\n" +
            "                        </tr>\n" +
            "                        </thead>\n" +
            "                        <tbody id=\"tbodyDataDivA\">\n" +
            "                        <tr>\n" +
            "                            <td>1</td>\n" +
            "                            <td>耐克潮牌鞋</td>\n" +
            "                            <td><img src=\"../cwjy/img/avatars/avatar-2.jpg\" style=\"width: 40px;height: 40px;\"></td>\n" +
            "                            <td>999</td>\n" +
            "                            <td >888</td>\n" +
            "                            <td>F1333457</td>\n" +
            "                            <td>888</td>\n" +
            "                        </tr>\n" +
            "                        <tr>\n" +
            "                            <td>1</td>\n" +
            "                            <td>耐克潮牌鞋</td>\n" +
            "                            <td><img src=\"../cwjy/img/avatars/avatar-2.jpg\" style=\"width: 40px;height: 40px;\"></td>\n" +
            "                            <td>999</td>\n" +
            "                            <td>F1333457</td>\n" +
            "                            <td>2018-12-12</td>\n" +
            "                            <td>888</td>\n" +
            "                        </tr>\n" +
            "                        </tbody>\n" +
            "                    </table>";
        let modelAction = "  <button type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">关闭</button>\n" +
            "                <!--<button type=\"button\" class=\"btn btn-primary\" >提交</button>-->";

        $('#modelHead').html(modelHead)
        $('#modelDiv').html(modelBody)
        $('#modelAction').html(modelAction)
        let order_item_entity = data.order_item_entity;
        let tbodyDataDivA = "";
        for (let i = 0; i < order_item_entity.length; i++) {
            let temp = "          <tr>\n" +
                "                            <td>" + (i + 1) + "</td>\n" +
                "                            <td>" + order_item_entity[i].commodity_entity.product_name + "</td>\n" +
                "                            <td><img src=\"http://localhost:8888/cwjy/images/" + order_item_entity[i].pic_path + "\" style=\"width: 40px;height: 40px;\"></td>\n" +
                "                            <td>" + order_item_entity[i].price + "</td>\n" +
                "                            <td >" + order_item_entity[i].num + "</td>\n" +
                "                            <td>" + order_item_entity[i].pic_type + "</td>\n" +
                "                            <td>" + order_item_entity[i].totle_fee + "</td>\n" +
                "                        </tr>\n";
            tbodyDataDivA += temp;
        }
        $('#tbodyDataDivA').html(tbodyDataDivA);

    }


    /*let modelHead = "";
    let modelBody = "";
    let modelAction = "";*/
    let refundId;
    let refundCommodityId;

    /**申请售后*/
    function sqsh(id, commodity_id) {
        let data = getOrderByIdData(id);
        let productName = "";
        let productImages = "";
        let productData = data.order_item_entity;
        for (let i = 0; i < productData.length; i++) {
            productName += productData[i].commodity_entity.product_name + " , ";
            let tempImages = "<img src=\"http://localhost:8888/cwjy/images/" + productData[i].pic_path + "\" style=\"width: 100px;height: 100px;\">";
            productImages += tempImages;
        }
        let modelHead = "  <h3 class=\"modal-title\" id=\"modelHeadText\" style=\"font-weight: bold;text-shadow: 1px 1px 3px #000000;\">\n" +
            "                    订单售后</h3>\n" +
            "                <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\">\n" +
            "                    <span aria-hidden=\"true\">×</span>\n" +
            "                </button>";
        let modelBody = "  <h3 style=\"text-shadow: 1px 1px 3px #000000;\">商品名称</h3>\n" +
            "                    <p class=\"text-muted\" style=\"font-weight: bold\">"+productName+"</p>\n" +
            "                    <h3 style=\"text-shadow: 1px 1px 3px #000000;\">商品图片</h3>\n" +
            "                    <p class=\"text-muted\" style=\"font-weight: bold\">"+productImages+" \n" +
            "                    <h3 style=\"text-shadow: 1px 1px 3px #000000;\">选择服务类型</h3>\n" +
            "                    <p id=\"returnButton\">\n" +
            "                        <button type=\"button\" id ='1' style=\"width: 49%;height: 100px;font-weight: bold\" class=\"btn btn-outline-secondary\">\n" +
            "                                我要退款(无需退货)\n" +
            "                                 <p>没收到或,或与卖家协商同意不用退货只退款</p>\n" +
            "                        </button>\n" +
            "                        <button type=\"button\" id ='2' class=\"btn btn-outline-secondary\" style=\"width:49%;height: 100px;font-weight: bold;background-color: #6c757d;color: #ffffff\">\n" +
            "                            我要退货退款\n" +
            "                            <p>已收到货,需要退还收到的货物</p>\n" +
            "                        </button>\n" +
            "                    </p>\n" +
            "                    <h3 style=\"text-shadow: 1px 1px 3px #000000;\">退款说明</h3>\n" +
            "                    <p class=\"text-muted\" style=\"font-weight: bold\">\n" +
            "                        <textarea style=\"resize: none;width: 70%;height: 100px;\" id='refund_instructions'></textarea>\n" +
            "                    </p>";
        let modelAction = " <button type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">关闭</button>\n" +
            "                 <button type=\"button\" class=\"btn btn-primary\" id='submitButton' onclick='refund()'>提交</button>";
        $('#modelHead').html(modelHead)
        $('#modelDiv').html(modelBody)
        $('#modelAction').html(modelAction)
        $('#returnButton button').unbind("click")
        $('#returnButton button').click(function () {
            $("#returnButton button").each(function () {
                $(this).css("background-color", "#ffffff")
                $(this).css("color", "#6c757d")
            })
            $(this).css("background-color", "#6c757d")
            $(this).css("color", "#ffffff")
        })
        refundId = id;
        refundCommodityId = commodity_id;
    }

    /**售后申请*/
    function refund() {
        let refund_instructions = $('#refund_instructions').val();
        let refund_type = 1;
        $("#returnButton button").each(function () {
            let background = $(this).css("background-color");
            if (background === 'rgb(108, 117, 125)') {
                refund_type = $(this)[0].id;
            }
        });
        let json = {
            "order_id": refundId,
            "commodity_id": refundCommodityId,
            "refund_instructions": refund_instructions,
            "refund_type": refund_type
        }
        $.ajax({
            type: 'post',
            async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
            url: 'http://localhost:8888/cwjy/OrderReturn/insert',    //请求发送到Servlet
            contentType: 'application/json;charset=UTF-8',//指定消息请求类型
            data: JSON.stringify(json),
            timeout: 10000,    //超时10s
            success: function (res) { returnLogin(res);
                if (res.data > 0) {
                    alert("退款申请成功")
                    window.location.reload();
                } else {
                    if (parseInt(res.code) === 500) {
                        alert(res.data)
                        return;
                    }
                    alert("申请退款失败")
                }
            },
            error: function (errorMsg) {
                //请求失败时执行该函数
                alert('数据请求失败!');
            }
        });


    }

    /**立即付款*/
    function ljfk() {
        if (confirm('是否确认付款?')) {
        }
    }

    let descriptive_match_score = 0;
    let logistics_service_score = 0;

    /**订单评价*/
    function ddPJ(id) {
        let data  = getOrderByIdData(id);
        let productName = "";
        let productImages = "";
        let productData = data.order_item_entity;
        for (let i = 0; i < productData.length; i++) {
            productName += productData[i].commodity_entity.product_name + " , ";
            let tempImages = "<img src=\"http://localhost:8888/cwjy/images/" + productData[i].pic_path + "\" style=\"width: 100px;height: 100px;\">";
            productImages += tempImages;
        }
        let modelHead = " <h3 class=\"modal-title\" id=\"modelHeadText\" style=\"font-weight: bold;text-shadow: 1px 1px 3px #000000;\">\n" +
            "                    订单评价</h3>\n" +
            "                <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\">\n" +
            "                    <span aria-hidden=\"true\">×</span>\n" +
            "                </button>";
        let modelBody = "<h3 style=\"text-shadow: 1px 1px 3px #000000;\">商品名称</h3>\n" +
            "                    <p class=\"text-muted\" style=\"font-weight: bold\">"+productName+"</p>\n" +
            "                    <h3 style=\"text-shadow: 1px 1px 3px #000000;\">商品图片</h3>\n" +
            "                    <p class=\"text-muted\" style=\"font-weight: bold\">"+productImages+""+
            "                    <h3 style=\"text-shadow: 1px 1px 3px #000000;\">商品评价</h3>\n" +
            "                    <p class=\"text-muted\" style=\"font-weight: bold\">\n" +
            "                        <span data-feather=\"star\" style=\"color: orange\"></span>\n" +
            "                        <span data-feather=\"star\" style=\"color: orange\"></span>\n" +
            "                        <span data-feather=\"star\" style=\"color: orange\"></span>\n" +
            "                        <span data-feather=\"star\" style=\"color: orange\"></span>\n" +
            "                        <span data-feather=\"star\"></span>\n" +
            "                    </p>\n" +
            "                    <h3 style=\"text-shadow: 1px 1px 3px #000000;\">评价商品</h3>\n" +
            "                    <p class=\"text-muted\" style=\"font-weight: bold\">\n" +
            "                        <textarea style=\"width: 60%;height: 120px\" id='information'></textarea>\n" +
            "                    </p>\n" +
            "                    <div id=\"pjfu\">\n" +
            "                        <h3 style=\"text-shadow: 1px 1px 3px #000000;\">描述相符</h3>\n" +
            "                        <p class=\"text-muted\" style=\"font-weight: bold\">\n" +
            "                        <div>\n" +
            "                            <span><button type=\"button\" data-feather=\"star\" id=\"msxf1\"></button></span>\n" +
            "                            <span><button type=\"button\" data-feather=\"star\" id=\"msxf2\"></button></span>\n" +
            "                            <span><button type=\"button\" data-feather=\"star\" id=\"msxf3\"></button></span>\n" +
            "                            <span><button type=\"button\" data-feather=\"star\" id=\"msxf4\"></button></span>\n" +
            "                            <span><button type=\"button\" data-feather=\"star\" id=\"msxf5\"></button></span>\n" +
            "                        </div>\n" +
            "                        </p>\n" +
            "\n" +
            "                        <h3 style=\"text-shadow: 1px 1px 3px #000000;\">物流服务</h3>\n" +
            "\n" +
            "                        <p class=\"text-muted\" style=\"font-weight: bold\">\n" +
            "                        <div>\n" +
            "                            <span><button type=\"button\" data-feather=\"star\" id=\"wlfw1\"></button></span>\n" +
            "                            <span><button type=\"button\" data-feather=\"star\" id=\"wlfw2\"></button></span>\n" +
            "                            <span><button type=\"button\" data-feather=\"star\" id=\"wlfw3\"></button></span>\n" +
            "                            <span><button type=\"button\" data-feather=\"star\" id=\"wlfw4\"></button></span>\n" +
            "                            <span><button type=\"button\" data-feather=\"star\" id=\"wlfw5\"></button></span>\n" +
            "                        </div>\n" +
            "                        </p>";
        let modelAction = "   <button type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">关闭</button>\n" +
            "                 <button type=\"button\" class=\"btn btn-primary\" onclick='addProductReviews(\"" + id + "\")'>提交</button>";
        $('#modelHead').html(modelHead)
        $('#modelDiv').html(modelBody)
        $('#modelAction').html(modelAction)
        feather.replace();
        $('#pjfu span').unbind("click");
        $('#pjfu span').click(function () {
            let evaluation = $(this).children();
            let evaluationId = evaluation[0].id;
            let index = parseInt(evaluationId.substring(evaluationId.length - 1, evaluationId.length));
            for (let i = 1; i <= 5; i++) {
                $('#' + evaluationId.substring(0, evaluationId.length - 1) + i).css("color", "");
            }
            for (let i = 1; i <= index; i++) {
                $('#' + evaluationId.substring(0, evaluationId.length - 1) + i).css("color", "orange");
            }
            let count = 0;
            $(this).parent().find("span").each(function () {
                let colorDemo = $(this).children().css("color")
                if (colorDemo === "rgb(255, 165, 0)") {
                    count++;
                }
            })
            if (evaluationId.indexOf("msxf") !== -1) {
                descriptive_match_score = count;

            } else {
                logistics_service_score = count;
            }
        })
    }

    /**增加评论*/
    function addProductReviews(id) {
        let data = getOrderByIdData(id);
        let commodity_id_array = [];
        let commidityItem = data.order_item_entity;
        for (let i = 0; i < commidityItem.length; i++) {
            commodity_id_array[i] = commidityItem[i].item_id;
        }
        let information = $('#information').val();
        let json = {
            "information": information, "descriptive_match_score": descriptive_match_score,
            "logistics_service_score": logistics_service_score, "order_id": id,
            "commodity_id": data.commodity_id,commodity_id_array:commodity_id_array
        };
        let url = "http://localhost:8888/cwjy/ProductReviews/insert";
        let success = "评价成功！";
        let error = "评价失败!";
        ajaxAddUpdate(url, json, success, error)

    }

    function ajaxAddUpdate(url, json, success, error) {
        $.ajax({
            type: 'post',
            async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
            url: url,    //请求发送到Servlet
            contentType: 'application/json;charset=UTF-8',//指定消息请求类型
            data: JSON.stringify(json),
            timeout: 10000,    //超时10s
            success: function (res) { returnLogin(res);
                if (res.data > 0) {
                    alert(success)
                    window.location.reload();
                } else {
                    if (parseInt(res.code) === 500) {
                        alert(res.data)
                    } else {
                        alert(error)
                    }
                }
            },
            error: function (errorMsg) {
                //请求失败时执行该函数
                alert('数据请求失败!');
            }
        });
    }


    function addType() {
        addNodeMessage("")
        feather.replace();
        initClassificationDetailedClick();
    }

    function addNodeMessage(name) {
        let temp = "    <div class=\"col-md-12\" >\n" +
            "                                    <div class=\"col-md-11\" style=\"float: left\">\n" +
            "                                        <input type=\"text\" class=\"form-control \"\n" +
            "                                               placeholder=\"类型名称\" value='" + name + "' style=\"margin-bottom: 10px\">\n" +
            "                                    </div>\n" +
            "                                    <div class=\"col-md-1\" style=\"float: left\">\n" +
            "                                   <span>     <button type=\"button\" data-feather=\"x-circle\"\n" +
            "                                                style=\"float: right;margin-top: 15%;color: red\"></button>\n" +
            "                                    </div></span>\n" +
            "                                </div>";
        $('#classification_detailed').append(temp)
    }

    function initClassificationDetailedClick() {
        $('#classification_detailed span').unbind("click")
        $('#classification_detailed span').click(function () {
            if (confirm('是否删除该节点?')) {
                $(this).parent().parent().remove()
            }
        })
    }

    initClassificationDetailedClick();

    function addData() {
        let classification_name = $('#classification_name');
        let type_name = $('#classification_detailed')
        type_name.find("input").each(function () {
        })
    }

    function initMode(onType) {
        let modiv = "<div class=\"mb-3 col-md-12\">\n" +
            "                            <label class=\"form-label\" for=\"classification_name\">类别名称</label>\n" +
            "                            <input type=\"email\" class=\"form-control\" id=\"classification_name\" placeholder=\"类别名称\">\n" +
            "                        </div>\n" +
            "                        <div class=\"mb-3  col-md-12\">\n" +
            "                            <label class=\"form-label\">类型名称</label>\n" +
            "                            <button type=\"button\" class=\"form-label\" for=\"type_name\" data-feather=\"plus-circle\"\n" +
            "                                    style=\"float: right\" onclick=\"addType()\"></button>\n" +
            "                            <div id=\"classification_detailed\">\n" +
            "                                <div class=\"col-md-12\">\n" +
            "                                    <div class=\"col-md-11\" style=\"float: left\">\n" +
            "                                        <input type=\"text\" class=\"form-control \"\n" +
            "                                               placeholder=\"类型名称\" style=\"margin-bottom: 10px\">\n" +
            "                                    </div>\n" +
            "                                    <div class=\"col-md-1\" style=\"float: left\">\n" +
            "                                        <span>\n" +
            "                                        <button type=\"button\" data-feather=\"x-circle\"\n" +
            "                                                style=\"float: right;margin-top: 15%;color: red\"\n" +
            "                                        ></button>\n" +
            "                                            </span>\n" +
            "                                    </div>\n" +
            "                                </div>\n" +
            "                            </div>\n" +
            "                        </div>";
        $('#modelDiv').html(modiv)

        let modelHead = " <h3 class=\"modal-title\" id='modelHeadText'>类别增加</h3>\n" +
            "                <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\">\n" +
            "                    <span aria-hidden=\"true\">&times;</span>\n" +
            "                </button>";

        $('#modelHead').html(modelHead)

        let modelAction = " <button type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">Close</button>\n" +
            "                <button type=\"button\" class=\"btn btn-primary\" onclick=\"" + onType + "\">Save changes</button>";
        $('#modelAction').html(modelAction)
        feather.replace();
    }


    function initModeViewDetails() {
        let modelHead = "<h3 class=\"modal-title\">类别详细</h3>\n" +
            "                   <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\">\n" +
            "                       <span aria-hidden=\"true\">&times;</span>\n" +
            "                   </button>";
        let modelDiv = "   <h1>类别名称</h1>\n" +
            "                    <p class=\"text-muted\">Etiam rhoncus. Maecendio et ante tincidunt tempus. Donec vitae sapien ut libero.</p>\n" +
            "                    <h1>类型详细</h1>\n" +
            "                    <p class=\"text-muted\">Etiam rhoncus. Maecenatincidunt tempus. Donec vitae sapien ut libero.</p>\n" +
            "                    <p class=\"text-muted\">Etiam rhoncus. Maecenatincidunt tempus. Donec vitae sapien ut libero.</p>\n" +
            "                    <p class=\"text-muted\">Etiam rhoncus. Maecenatincidunt tempus. Donec vitae sapien ut libero.</p>\n" +
            "                    <p class=\"text-muted\">Etiam rhoncus. Maecenatincidunt tempus. Donec vitae sapien ut libero.</p>";
        let modelAction = "  <button type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">Close</button>";
        $('#modelHead').html(modelHead)
        $('#modelDiv').html(modelDiv)
        $('#modelAction').html(modelAction)
    }

    function updateData() {
        alert('修改成功')
    }


</script>

</body>
</html>